package com.songjia.common.model.base;

import java.io.Serializable;

/**
 * 
 * 
 * @Description: 接口返回报文数据封装bean
 *
 * @author: songjia
 * @date: 2017年5月5日 下午6:29:56
 */
public class ResponseInfo implements Serializable {

	private static final long serialVersionUID = -2210269174549937804L;

	// 成功状态码
	public static final Integer SUCCESS_C0DE = Integer.valueOf(1);

	// 失败状态码
	public static final Integer FAIL_CODE = Integer.valueOf(-1);

	// 接口状态码
	private Integer code;

	// 提示消息
	private String message;

	// 接口业务数据
	private Object result;

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public ResponseInfo(Integer code, String message) {
		super();
		this.code = code;
		this.message = message;
	}

	public ResponseInfo(Integer code, Object result) {
		super();
		this.code = code;
		this.result = result;
	}

	public ResponseInfo(Integer code) {
		super();
		this.code = code;
	}

	public ResponseInfo() {
		super();
	}

	public static ResponseInfo success(Object result) {
		return new ResponseInfo(ResponseInfo.SUCCESS_C0DE, result);
	}

	public static ResponseInfo success() {
		return new ResponseInfo(ResponseInfo.SUCCESS_C0DE);
	}

	public static ResponseInfo fail(String errorMsg) {
		return new ResponseInfo(ResponseInfo.FAIL_CODE, errorMsg);
	}

	public static ResponseInfo fail(Integer errCode) {
		if (errCode == SUCCESS_C0DE) {
			return new ResponseInfo(FAIL_CODE);
		}
		return new ResponseInfo(errCode);
	}

	public static ResponseInfo fail(Integer errCode, String errMessage) {
		return new ResponseInfo(errCode, errMessage);
	}
}
